﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Routing;
using Enterprise.Management.Common;
using Enterprise.Management.Data;

namespace System.Web.Mvc.Html
{
    public static class MenuHelper
    {
        public static MvcHtmlString MenuButton(this HtmlHelper html, string name, string image, string url, int type)
        {
            StringBuilder content = new StringBuilder();
            content.Append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"menubuttontable\">");
            content.Append("<tr><td>");
            content.Append(string.Format(@"<a href=""javascript:void(0);"" onclick=""go('{2}',{3})""><img src=""{1}"" alt=""{0}"" /></a>", name, image, url, type));
            content.Append("</td></tr>");
            content.Append("<tr><td>");
            content.Append(string.Format(@"<a href=""javascript:void(0);"" onclick=""go('{1}',{2})"">{0}</a>", name, url, type));
            content.Append("</td></tr>");
            content.Append("</table>");


            return MvcHtmlString.Create(content.ToString());
        }

        public static MvcHtmlString Navigation(this HtmlHelper html, params string[] subitems)
        {
            StringBuilder content = new StringBuilder();
            content.Append(@"<div id=""navi-container"">");

            if (subitems.Length > 0)
            {
                content.Append(string.Format(@"<a href=""{0}"" class=""navi-item-link"">首页</a>", UrlBuilder.GenerateUrl("Index", "Home")));

                for (int i = 0; i < subitems.Length - 2; i += 2)
                {
                    content.Append(@"<span class=""navi-split"">></span>");
                    content.Append(string.Format(@"<a href=""{1}"" class=""navi-item-link"">{0}</a>", subitems[i], subitems[i + 1]));
                }

                content.Append(@"<span class=""navi-split"">></span>");
                content.Append(string.Format(@"<span class=""navi-item-normal"">{0}</span>", subitems[subitems.Length - 1]));
            }
            else
            {
                content.Append(@"<span class=""navi-item-normal"">首页</span>");
            }
            content.Append("</div>");

            return MvcHtmlString.Create(content.ToString());
        }


    }
}